/**
 * Created by zander on 2017/12/6.
 */
function getProject() {
    var a = document.getElementById("Project");
    var b = a.options[a.selectedIndex].value;
    return b;
}

function clearInfo() {
    var patrn1 = /^[0-9]*[1-9][0-9]*$/;
    var patrn = /^[0-9a-zA-Z]/;
    // var patrn = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)|(^\+?[1-9][0-9]*$)/;
    var inputPhone = $('#inputPhone').val();
    var inputId = $('#inputID').val();
    if (inputPhone == ""){
        alert("手机号为空");
        return false;
    }else if (inputId == ""){
        alert("身份证号为空");
        return false;
    }else if (!patrn1.test(inputPhone)){
        alert("手机号只能输入数字");
        return false;
    }else if (!patrn.test(inputId)){
        alert("身份证号格式不正确");
        return false;
    }
    document.getElementById('res').innerText = '';
    var localStorage = window.sessionStorage;
    var project = getProject();
    var phone = document.getElementById('inputPhone').value;
    var identifier = document.getElementById('inputID').value;
    var username = localStorage.getItem('username');
    console.log(username)

    sure(username,project, phone, identifier);
}
function sure(username,project, phone, identifier) {
    bootbox.confirm({
        size: "small",
        message: "是否确认清除用户所有数据?",
        callback: function (result) {
            if (result == true) {
                $.ajax({
                    type: "POST",
                    url: "/intest/v1/rd/clearuserInfo",
                    data: {username:username,project: project, phone: phone, identifier: identifier},
                    dataType: "json",
                    beforeSend:function(){
                        $("body").mLoading("show");
                    },
                    success: function (ret) {
                        if (ret.status == "0000") {
                            $("body").mLoading("hide");
                            $("#res").append(ret.message);
                        }else {
                            $("body").mLoading("hide");
                            $("#res").append(ret.message);
                        }
                    },
                    error: function() {
                        $("body").mLoading("hide");
                        $("#res").append("Error 500,请联系开发人员！");
                    }
                });
            }
        }
    })
}

function check(e) {
    var id = $(e).attr('id');
    var number = document.getElementById(id).value;
    if (number == "") {
        return true
    }
    // var patrn = /^\+?[1-9][0-9]*$/;
    var patrn = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)|(^\+?[1-9][0-9]*$)/;
    if (!patrn.test(number)) {
        alert("只允许输入数字！");
        $(e).text("");
    }
}
